﻿using System;
using System.Configuration;
using System.Data;
using System.Collections.Generic;
using System.Text;
using KPIS.DBM;
using KPIS.GERP.ESS.MODEL;

namespace KPIS.GERP.ESS.DAL
{
    public class D_HrmJobsites
    {
        public D_HrmJobsites()
        {

        }

        public DataTable GetList()
        {
            return GetList(null);
        }

        public DataTable GetList(string scope)
        {
            IDBManager dbManager = new DBManager(SystemInfo._DataProvider, SystemInfo._ConnectionString);

            try
            {
                dbManager.CreateParameters(2);
                dbManager.AddParameters(0, "@RecordStatus", SystemInfo._DeleteRecordStatus);
                dbManager.AddParameters(1, "@scope", scope == null ? DBNull.Value : (object)scope);

                string sql = "select j.job_site_seq, j.job_site_name"
                    + " from hrm_mp_job_sites j"
                    + " left join hrm_mp_work_areas wa on j.work_area_seq = wa.work_area_seq"
                    + " where j.record_status not like @RecordStatus"
                    + " and j.job_site_type_seq = 2"
                    + " and j.job_site_level_seq = 3"
                    + " and j.gfmis_code is not Null"
                    + (!string.IsNullOrEmpty(scope) ? " and wa.scope_seq = @scope" : "")
                    + " order by j.job_site_name";
                DataTable dt = new DataTable();
                dbManager.Open();
                dt = dbManager.ExecuteDataSet(CommandType.Text, sql).Tables[0];
                return dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dbManager.Dispose();
            }
        }

        public DataTable GetInfo(string job_site_seq)
        {
            IDBManager dbManager = new DBManager(SystemInfo._DataProvider, SystemInfo._ConnectionString);

            try
            {
                dbManager.CreateParameters(1);
                dbManager.AddParameters(0, "@job_site_seq", job_site_seq);

                string sql = "select j.job_site_seq, j.job_site_name"
                    + " from hrm_mp_job_sites j"
                    + " where j.job_site_seq = @job_site_seq";
                DataTable dt = new DataTable();
                dbManager.Open();
                dt = dbManager.ExecuteDataSet(CommandType.Text, sql).Tables[0];
                return dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dbManager.Dispose();
            }
        }
    }
}
